//
//  Mp3Player.m
//  myfish
//
//  Created by EmberWei on 2018/6/6.
//  Copyright © 2018年 EmberWei. All rights reserved.
//

#import "Mp3Player.h"

@interface Mp3Player()
@property (strong, nonatomic)  AVAudioPlayer *player;
@end

@implementation Mp3Player

+(Mp3Player*)initWithName:(NSString*)name
{
    Mp3Player *mp3 = [[Mp3Player alloc]init];
    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
    NSURL *url = [[NSURL alloc]initFileURLWithPath:path];
    mp3.player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
    [mp3.player prepareToPlay];
    mp3.player.numberOfLoops = -1;
    return mp3;
}

-(void)play
{
    [self.player play];
}


-(void)pause
{
     [self.player pause];
}

-(void)stop
{
     [self.player stop];
}

@end
